package com.chenyun.rpc.feign.config;

import com.chenyun.common.factory.YAMLPropertySourceFactory;
import feign.Logger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.Serializable;

/**
 * feign配置类
 * @author: Lonni
 * @date: 2022/11/18 0018 15:56
 */

@Configuration
@EnableFeignClients(basePackages = {"com.chenyun", "com.lonni"})
//避免其他接口扫描不到,所以将此条件下移
//@ConditionalOnProperty(value = "chenyun.rpc.type",havingValue = "feign",matchIfMissing = true)

@PropertySource(value = "classpath:config/application-feign.yml",factory = YAMLPropertySourceFactory.class)
@Slf4j
public class FeignConfig implements Serializable {

    private final static int DEFAULT_CONNECTIONS = 200;

    public FeignConfig(){
        log.info("加载FeignConfig....");
    }

    /**
     * feign日志级别
     * FULL:所有
     * NONE，默认的级别，表示不打印
     * BASIC，仅记录请求方法和URL以及响应状态代码和执行时间
     * HEADERS，记录基本信息以及请求和响应标头
     * @return
     */
    @Bean
    @ConditionalOnProperty(value = "chenyun.rpc.type",havingValue = "feign",matchIfMissing = true)
    Logger.Level feignLoggerLevel()
    {
        return Logger.Level.FULL;
    }


    @Bean
    @ConditionalOnProperty(value = "chenyun.rpc.type",havingValue = "feign",matchIfMissing = true)
    public SatokenFeignRequestInterceptor requestInterceptor(){
        return new SatokenFeignRequestInterceptor();
    }
}



